package com.tbit.uqbike.client.controller.provide;

import com.tbit.uqbike.client.service.pushMsg.WxPushService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Objects;

/**
 * 外部调用 - 微信小程序服务消息推送
 *
 * @author <a href="mailto:zhang.zhiliang@tbit.com.cn">Zhang ZhiLiang</a>
 * @version 1.0
 * @see <a href="http://adsl1.tbit.com.cn:21490/pages/viewpage.action?pageId=82182491">订单号规范</a>
 * @since 2024/10/16
 */
@Slf4j
@RequestMapping("/wx")
@RestController
public class WxPushMsgController {

    private final WxPushService wxPushService;
    private final String secret;

    public WxPushMsgController(WxPushService wxPushService) {
        this.wxPushService = wxPushService;
        this.secret = "36987";
    }

    @PostMapping("/pushNotReturnBikeMsg")
    public boolean pushNotReturnBikeMsg(String orderNO,String secret){
        if (valid(secret)){
            log.info("未还车服务消息推送");
            wxPushService.pushNotReturnBikeMsg(orderNO);
            return true;
        }
        return false;
    }

    private boolean valid(String secret){
        return Objects.equals(this.secret,secret);
    }
}
